package algorithm.sort.array;

import java.util.Random;

/**
 * @program: algorithm-data-structure
 * @description:
 * @author: Keyu Li
 * @create: 2021-08-31 22:33
 **/

public class capitalLetterSort {
    final static int ARRAY_NUMBER = 100;

    public static void main(String[] args) {
        // create a array
        char[] arr = createArray(ARRAY_NUMBER);
        printArr(arr);
        sort(arr);
        printArr(arr);
    }

    private static char[] createArray(int length) {
        char[] arr = new char[length];
        Random rd = new Random();
        for (int i = 0; i < length; i++) {
            int letter = rd.nextInt(26);
            int capital = rd.nextInt(2);
            arr[i] = (char) ('a'+letter+capital*('A'-'a'));
        }
        return arr;
    }

    private static void sort(char[] arr) {
        char pivot = 'Z';
        int i=0, j=0;
        char temp;
        while(j<arr.length){
            if (arr[j]<pivot){
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
                i++;
            }
            j++;
        }
    }

    private static void printArr(char[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}
